24. CODE: Parse Lines from the File

Parse Lines from the File

Now that you are able to read a board line by line from a file, you will want to parse these lines and store them in a vector<int> . In this exercise, you will focus on a helper function to do this string parsing.

We have included a test in the main to ensure that the function is working correctly. If everything works, you should see:

----------------------------------------------------------
TestParseLine: passed
----------------------------------------------------------

To Complete This Exercise:

Write a vector<int> ParseLine function which accepts a string as an argument. Use std::istringstream to parse the line by comma char s, and store the int s in a vector<int> . ParseLine should return the vector after parsing.

Note: you will need to #include <sstream> to use istringstream . Additionally, you may want to add using std::istringstream; to your program. Finally, remember that each line of the board will look something like: 1,0,0,0,0, , so you may want to stream an int and a char with each pass through a while loop.

Workspace

This section contains either a workspace (it can be a Jupyter Notebook workspace or an online code editor work space, etc.) and it cannot be automatically downloaded to be generated here. Please access the classroom with your account and manually download the workspace to your local machine. Note that for some courses, Udacity upload the workspace files onto https://github.com/udacity , so you may be able to download them there.

Workspace Information:

  • Default file path:
  • Workspace type: generic
  • Opened files (when workspace is loaded): n/a
  • userCode:

    export CXX=g++-7
    export CXXFLAGS=-std=c++17
    g++() {
    /usr/bin/g++-7 -std=c++17 "$1"
    }
    export -f g++